package DataValidatorSchema::Bar;
use strict;
use base qw/ DBIx::Class /;

__PACKAGE__->load_components( qw/ Component::DataValidator Core / );
__PACKAGE__->table( 'bar' );
__PACKAGE__->resultset_class( qw/ DBIx::Class::ResultSet::DataValidator / );

__PACKAGE__->add_validation_profiles( {
    test_no_method => {
        required => [ qw/ id / ],
        constraint_methods => {
            id => 'named:no_such_method',
        },
        filters => [ qw/ trim / ]
    },
    test_static_method => {
        required => [ qw/ id / ],
        constraint_methods => {
            id => 'named:test_static',
        },
        filters => [ qw/ trim / ]
    },
    test_runtime_method => {
        required => [ qw/ id / ],
        constraint_methods => {
            id => 'named:test_runtime',
        },
        filters => [ qw/ trim / ]
    },
    test_both_metod => {
        required => [ qw/ id / ],
        constraint_methods => {
            id   => 'named:test_static',
            name => 'named:test_runtime',
        },
        filters => [ qw/ trim / ]
    }
} );

__PACKAGE__->add_validation_methods( {
    test_static => sub { return 1 }
} );

__PACKAGE__->add_validated_column_class( {
    some_character => {
        default_value => 'lala',
        validation => {
            constraint => sub {
                my ( $dv, $v ) = @_;
                return $v eq 'lala' || $v =~ /^ok/;
            }
        }
    }
} );

__PACKAGE__->disable_native_validation( 1 );


__PACKAGE__->add_columns(
    id => {
        validation => {
            required => 1,
            constraint => qr~^\d+$~
        }
    },
    'name' => 'class:some_character'
);
__PACKAGE__->set_primary_key( qw/ id / );

1;
